package com.sky.service.impl;

import com.sky.result.Result;
import com.sky.service.ShopService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;

@Service
@Slf4j
public class ShopServiceImpl implements ShopService {
    public static final String KEY = "SHOP_STATUS";

    @Autowired
    private StringRedisTemplate redisTemplate;

    /**
     * 设置店铺状态
     * @param status
     * @return
     */
    @Override
    public Result setStatus(Integer status){
        log.info("店铺的状态:{}",status == 1 ? "营业":"打烊");
        redisTemplate.opsForValue().set(KEY,status+"");
        return Result.success();
    }

    /**
     * 获取店铺状态
     * @return
     */
    @Override
    public Result<Integer> getStatus(){
        String status = redisTemplate.opsForValue().get(KEY);
        log.info("店铺的状态:{}",Integer.parseInt(status) == 1 ? "营业":"打烊");
        return Result.success(Integer.parseInt(status));
    }
}
